<#include "../../inc/header.ftl" />
<#import "/META-INF/spring.ftl" as spring />
<#import "/META-INF/mspring.ftl" as mspring />
<script type="text/javascript">
	$(document).ready(function(){
		var cache = {};
	    function split( val ) {
	      	return val.split( /,\s*/ );
	    }
	    function extractLast( term ) {
	      	return split(term).pop();
	    }
	 
	 	var ele = document.getElementById('user.name');
	    $(ele).bind( "keydown", function(event){})
      	.autocomplete({
      		minLength: 1,
	        source: function (request, response) {
	        	var term = request.term;
	            if ( term in cache ) {
	              response( cache[ term ] );
	              return;
	            }
	            $.ajax({
	                type: "POST",
	                url: mlog.variable.base+"/admin/post/catalog/userAutocomplete?name=" +  extractLast(request.term) ,
	                contentType: "application/json; charset=utf-8",
	                dataType: "json",
	                success: function (rsp) {
	                	cache[term] = $.map(rsp.data.users, function(item){
	        				return item.name
	        			});
	                	response($.ui.autocomplete.filter(
                			$.map(rsp.data.users, function(item){
                				return item.name
                			}), extractLast(request.term))
                		);
	                },
	                error: function(){
	                }
	            });
			},
	        focus: function() {
	          	return false;
	        },
	        select: function( event, ui ) {
	        	var terms = split( this.value );
	          	terms.pop();
	          	terms.push( ui.item.value );
	          	terms.push( "" );
	          	this.value = terms.join( ", " );
	          	return false;
	        }
        });
	});
</script>
<div id="error" class="message error" style="display:none;"></div>
<form class="form" id="catalogForm" action="${base}/admin/post/catalog/create/save" method="POST">
	<@spring.bind "postCatalog" />
	<table class="formtable">
		<tr>
			<td class="fieldlabel" style="width:60px;">编号</td>
			<td>
				<@spring.formInput path="postCatalog.id" attributes='class="textinput" style="width:98%;" disabled="disabled"' defaultValue="自动生成"  />
			</td>
		</tr>
		<tr>
			<td class="fieldlabel" style="width:60px;">创建时间</td>
			<td>
				<@spring.formInput path="postCatalog.createTime" attributes='class="textinput" style="width:98%;" disabled="disabled"' defaultValue="当前时间" />
			</td>
		</tr>
		<tr>
			<td class="fieldlabel" style="width:60px;">名称</td>
			<td>
				<@spring.formInput path="postCatalog.name" attributes='class="textinput" style="width:98%;" validate=\'{required: true, postCatalogNameExists:{user:${currentUser.id}}, messages:{required:"请输入分类名称", postCatalogNameExists:"分类名字已经存在"}}\'' />
			</td>
		</tr>
		<tr>
			<td class="fieldlabel" style="width:60px;">排序</td>
			<td>
				<@spring.formInput path="postCatalog.order" attributes='class="textinput" style="width:98%;" validate=\'{required: false, digits: true, messages:{digits:"排序号必须为正整数"}}\'' />
			</td>
		</tr>
		<tr>
			<td class="fieldlabel" style="width:60px;">描述</td>
			<td>
				<@spring.formTextarea path="postCatalog.description" attributes='class="textinput" style="width:98%;"' />
			</td>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;">
				<input type="submit" class="btn" value=" 提交 " />
			</td>
		</tr>
	</table>
</form>
<script type="text/javascript">
	$(document).ready(function(){
		//斑马线
		var tables=document.getElementsByTagName("table");
		var b=false;
		for (var j = 0; j < tables.length; j++){
			var cells = tables[j].getElementsByTagName("tr");
			//cells[0].className="color3";
			b=false;
			for (var i = 0; i < cells.length; i++){
				if(b){
					cells[i].className="color2";
					b=false;
				}
				else{
					cells[i].className="color3";
					b=true;
				};
			};
		}
		
		mlog.form.validate({
			selector : "#catalogForm",
			errorLabelContainer : "#error",
			wrapper: 'li',
			onfocusout : false,
			onkeyup : false,
			onclick : false,
			success : function(){
				mlog.utils.scrollTop();
			}
		});
		
	});
</script>
<#include "../../inc/footer.ftl" />